Grokking JavaScript Fundamentals
Rate this course
Ask Author
Contribute
Back to course home

0% completed

Vote For New Content
Introduction
Who should take this course?
Course Overview
Introduction to JavaScript
JavaScript Basics
JavaScript - Hello World
JavaScript - Comments
Quiz
JavaScript Variables and Operators
JavaScript - Variables
JavaScript - Operators
Quiz
JavaScript Conditionals
Introduction to Conditional Statements in JavaScript
JavaScript - If...Else
JavaScript - Switch Case
Quiz
JavaScript Objects
Introduction to Objects in JavaScript
JavaScript - Number
JavaScript - Boolean
JavaScript - Math
JavaScript - Date
Quiz
Introductions to Function in JavaScript
JavaScript - Variable Scope
JavaScript - Default Parameters
JavaScript - Arrow Functions
Quiz
Introduction to Strings in JavaScript
JavaScript - String Methods
Introduction to Array in JavaScript
JavaScript - Array Methods
Quiz
Introduction to loops in JavaScript
JavaScript - for loop
JavaScript - while loop
JavaScript - do-while loop
JavaScript - for-in loop
JavaScript - for-of loop
JavaScript - Loop Control
Quiz
JavaScript - Maps
JavaScript - Sets
Quiz
Where to Go from Here
JavaScript - Number

The Number object in JavaScript is a wrapper object allowing you to work with numerical values. It provides properties and methods for mathematical operations, enabling you to perform computations and manage numeric data effectively.

Syntax

The Number object in JavaScript can be instantiated using the new keyword, followed by the Number() constructor. The new keyword creates a new instance of the Number object, wrapping the numeric value provided as an argument to the constructor.

var numInstance = new Number(value);
  • value: The numeric value you want to represent as a Number object. If the value cannot be converted into a number, it results in NaN.

Properties

The Number object comes with several built-in properties:

No.PropertyDescription
1MAX_VALUERepresents the largest positive numeric value representable in JavaScript.
2MIN_VALUERepresents the smallest positive numeric value representable in JavaScript.
3NaNRepresents "Not-a-Number" value.
4NEGATIVE_INFINITYRepresents negative infinity; returned on overflow.
5POSITIVE_INFINITYRepresents positive infinity; returned on overflow.
6EPSILONRepresents the difference between 1 and the smallest floating point number greater than 1.
7MAX_SAFE_INTEGERRepresents the maximum safe integer in JavaScript (2^53 - 1).
8MIN_SAFE_INTEGERRepresents the minimum safe integer in JavaScript (-(2^53 - 1)).

Number Instance Methods

Instance methods are called on instances of the Number object. Here are some notable instance methods:

No.Method NameDescription
1toFixed()Converts a number into a string, rounding to a specified number of decimals.
2toPrecision()Converts a number into a string with a specified length.
3toString()Converts a Number object to a string in a specified base.
4valueOf()Returns the primitive value of a Number object.

Number Static Methods

Static methods are called on the Number class itself, not on instances of the Number class.

No.Method NameDescription
1isFinite()Determines whether the passed value is a finite number.
2isInteger()Determines whether the passed value is an integer.
3isNaN()Determines whether the passed value is NaN.
4isSafeInteger()Determines whether the provided value is a safe integer.
5parseFloat()Parses an argument and returns a floating point number.
6parseInt()Parses a string argument and returns an integer of the specified radix.

Examples

Let's illustrate the usage of some instance and static methods:

MAX_VALUE Property:

Javascript

. . . .
  • Displays the largest positive numeric value representable in JavaScript.

Instance Method: toFixed()

Javascript

. . . .
  • toFixed(2) formats the num instance to a string with 2 decimal places.

Static Method: parseInt()

Javascript

. . . .
  • parseInt() parses the string str and returns the integer part.
Introduction to Objects in JavaScript
JavaScript - Boolean
Mark as Completed

On this page

Syntax

Properties

Number Instance Methods

Number Static Methods

Examples